package service;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * 
 * WebService Admin pour le router
 * 
 * @author Maurice & Topia
 * 
 */
public class Admin {

	private Admin() {
		// nothing
	}

	private static Admin singleton;

	public static Admin getInstance() {
		if (singleton == null) {
			singleton = new Admin();
		}
		return singleton;
	}

	public String addBusinessProcess(String s) throws Exception {

		try {
			File fichier = new File(s);
			if (fichier.exists()) {
				URL u = fichier.toURI().toURL();
				BusESB.getInstance().addBusinessProcess(u);
				return "BusinessProcess added correctly with BPEL following URL : " + u;
			} else {
				return "Given parameter doesn't match an existing file.";
			}
		} catch (MalformedURLException e) {
			throw new RuntimeException("Given parameter can't be converted in URL.");
		}
	}

	public String removeBusinessProcess(String id) {
		if (BusESB.getInstance().removeBusinessProcess(id)) {
			return "Business process deleted : " + id;
		} else {
			return "Can't delete business process : " + id + " because it's not referenced in the bus.";
		}
	}

}
